package com.zahb.qadx.ui.adapter;

import android.view.ViewGroup;
import android.widget.FrameLayout;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.util.AdapterUtilsKt;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.zahb.qadx.R;
import com.zahb.qadx.model.WorkExRequest;
import com.zahb.qadx.util.DisplayUtil;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;


public class WorkExperienceAdapter extends BaseQuickAdapter<WorkExRequest, BaseViewHolder>  {
    public WorkExperienceAdapter(int layoutResId, @Nullable List<WorkExRequest> data) {
        super(layoutResId, data);
        addChildClickViewIds(R.id.tvDelete, R.id.content);
    }

    @NotNull
    @Override
    protected BaseViewHolder createBaseViewHolder(@NotNull ViewGroup parent, int layoutResId) {
        if (layoutResId == R.layout.item_work_ex_content) {
            FrameLayout itemView = new FrameLayout(parent.getContext());
            FrameLayout backgroundView = new FrameLayout(parent.getContext());
            backgroundView.setBackgroundResource(R.drawable.corner8_white);
            itemView.addView(backgroundView);
            //设置margin时父控件必须存在
            ViewGroup.MarginLayoutParams layoutParams = (ViewGroup.MarginLayoutParams) backgroundView.getLayoutParams();
            layoutParams.leftMargin = DisplayUtil.dip2px(16f);
            layoutParams.topMargin = DisplayUtil.dip2px(16f);
            layoutParams.rightMargin = DisplayUtil.dip2px(16f);
            layoutParams.bottomMargin = 0;
            backgroundView.setLayoutParams(layoutParams);
            backgroundView.addView(AdapterUtilsKt.getItemView(backgroundView, R.layout.item_work_ex_content));
            return new BaseViewHolder(itemView);
        } else {
            return super.createBaseViewHolder(parent, layoutResId);
        }
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, WorkExRequest s) {

        baseViewHolder.setText(R.id.tvTime,s.startDate+" - "+s.getEndData())
                .setText(R.id.tvCompany,s.company)
                .setText(R.id.tvJob,s.job);




    }
}
